# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>
# Contributor: Andrew Sun <adsun701@gmail.com>

_realname=libcerf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.13
pkgrel=1
pkgdesc="Complex error functions, Dawson, Faddeeva, and Voigt function (mingw-w64)"
arch=('any')
url='https://jugit.fz-juelich.de/mlz/libcerf'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
source=("http://apps.jcns.fz-juelich.de/src/${_realname}/${_realname}-${pkgver}.tgz"
        "libcerf-fix-installation-dirs.patch"
        "libserf-fix-exports.patch")
sha256sums=('011303e59ac63b280d3d8b10c66b07eb02140fcb75954d13ec26bf830e0ea2f9'
            'f8b685bf73ce980dc0eedb66b8b5e376f3c79983acf197038d816cc51621e436'
            '3f3e5489a3bffab6f23609cf55cfec8c888f8e72988354747e00045d3d6848ee')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/libcerf-fix-installation-dirs.patch"
  patch -Np1 -i "${srcdir}/libserf-fix-exports.patch"
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=ON \
      -DLIB_INSTALL=ON \
      ../${_realname}-${pkgver}

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check || true
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  # License
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
